package zozopo.warehouse.flow;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.background.operator.operations.OperatorTB;
import zozopo.background.operator.operations.OperatorlimitedTB;
import zozopo.flow.comm.Flow;

import zozopo.warehouse.operations.ReceiptOS;
import zozopo.warehouse.operations.ReceiptTB;
import zozopo.warehouse.operations.ReceiptlistOS;
import zozopo.warehouse.operations.ReceiptlistTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class PreConfirmShipPriceFlowByShipnoAction extends ActionSupport implements Action,SessionAware{
	
	private static final String limitedCode ="FLOW.WAREHOUSE.RECEIPTLIST.CONFIRMSHIPPRICE";

	//传入参数
	
	private String flowCode = "";
	private String kind = "FLOW.WAREHOUSE.RECEIPTLIST";
	private int kindid ;
	private String shipno = "";
	private boolean iswrong = false;
	//传出参数
	private ReceiptlistTB receiptlist;
	private List<ReceiptTB> receiptList;
	
	
	
	private Map<Object, Object> session;
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	public String execute(){
		flowCode = limitedCode;
		String forward = SUCCESS;

		return forward;
		 
	}
	
	
	public void validate() {
		//权限处理
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			iswrong = true;
			return ; 
		} 
		
		//用户权限
		Map<String,OperatorlimitedTB> operatorlimitedMap = (Map<String,OperatorlimitedTB>)session.get("operatorlimitedMap");
		
		if(operatorlimitedMap.get(limitedCode) == null){
			addFieldError("errormessage","用户没有查看进货权限.");
			iswrong = true;
			return;
		}
		
		Flow flow = new Flow();
		
		try{
			ReceiptlistOS receiptlistOS = new ReceiptlistOS(flow.getConn());
			ReceiptOS receiptOS = new ReceiptOS(flow.getConn());
			
			receiptlist = receiptlistOS.getReceiptlistByShipno(shipno);
			
			if(receiptlist == null){   //如果没找到相关快递单数据
				
				
				addFieldError("errormessage","快递单号:"+shipno+"不存在.");
				iswrong = true;
				return;
			}
			
			
			receiptList = receiptOS.getListByReceiptlistId(receiptlist.getId_receiptlist());
			
			kindid = receiptlist.getId_receiptlist();
			
			if(!flow.isNextCode(kind, receiptlist.getId_receiptlist(), limitedCode)){  // 如果下次的流程值不同就跳出本次处理。 预防多人输入时发生错误。
				
				addFieldError("errormessage","快递单:"+shipno+"状态不对.");
				iswrong = true;
				return;
			}//*/
		}finally{
			flow.releaseConnection();
		}
		
		
	}
	
	public String getFlowCode() {
		return flowCode;
	}
	public void setFlowCode(String flowCode) {
		this.flowCode = flowCode;
	}
	public String getKind() {
		return kind; 
	}
	public void setKind(String kind) {
		this.kind = kind;
	}
	public int getKindid() {
		return kindid;
	}
	public void setKindid(int kindid) {
		this.kindid = kindid;
	}
	public ReceiptlistTB getReceiptlist() {
		return receiptlist;
	}
	public void setReceiptlist(ReceiptlistTB receiptlist) {
		this.receiptlist = receiptlist;
	}
	public List<ReceiptTB> getReceiptList() {
		return receiptList;
	}
	public void setReceiptList(List<ReceiptTB> receiptList) {
		this.receiptList = receiptList;
	}
	public String getShipno() {
		return shipno;
	}
	public void setShipno(String shipno) {
		this.shipno = shipno;
	}
	public boolean isIswrong() {
		return iswrong;
	}
	public void setIswrong(boolean iswrong) {
		this.iswrong = iswrong;
	}

	

}
